package com.caocaog.market.front;

import com.caocaog.market.annotation.IgnoreAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.Limit;
import org.jeecg.common.util.WxUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信小程序服务端api
 *
 * @author chechen
 * @date 2021-01-24
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(value = "wxApi", tags = "API微信小程序服务端")
@RequestMapping("/api/wx")
public class WxController {

    private final WxUtil wxUtil;

    @IgnoreAuth
    @Limit(key = "getAccessToken", period = 60, count = 10, name = "获取小程序AccessToken", prefix = "limit")
    @ApiOperation(value = "获取小程序AccessToken", notes = "获取小程序AccessToken")
    @GetMapping("getAccessToken")
    public Result<?> getAccessToken() {
        return Result.OK(wxUtil.getAccessToken());
    }

    @IgnoreAuth
    @Limit(key = "getWxCode", period = 60, count = 30, name = "获取小程序码", prefix = "limit")
    @ApiOperation(value = "获取店铺小程序码", notes = "获取店铺小程序码")
    @GetMapping("getShopWxCode")
    public Result<?> getShopWxCode(@RequestParam String shopId) {
        return Result.OK(wxUtil.getCodeUnlimited(shopId, null));
    }

    @IgnoreAuth
    @Limit(key = "getWxCode", period = 60, count = 30, name = "获取小程序码", prefix = "limit")
    @ApiOperation(value = "获取商品小程序码", notes = "获取商品小程序码")
    @GetMapping("getGoodsWxCode")
    public Result<?> getGoodsWxCode(@RequestParam String goodsId) {
        return Result.OK(wxUtil.getCodeUnlimited(null, goodsId));
    }

}
